package com.ruoyi.project.tool.swagger.AppApi;

import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.security.service.SysLoginService;
import com.ruoyi.framework.security.service.SysPermissionService;
import com.ruoyi.framework.security.service.TokenService;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.project.system.domain.SysUser;
import com.ruoyi.project.system.domain.vo.LoginVo;
import com.ruoyi.project.system.service.ISysMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 登录验证
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/appapi/")
public class LoginMobileController{
    @Autowired
    private SysLoginService loginService;

    @Autowired
    private ISysMenuService menuService;

    @Autowired
    private SysPermissionService permissionService;

    @Autowired
    private TokenService tokenService;

    /**
     * 登录方法
     * 
//     * @param username 用户名
//     * @param password 密码
//     * @param captcha 验证码
//     * @param uuid 唯一标识
     * @return 结果
     */
    @PostMapping("/login")
    public AjaxResult login(@RequestBody LoginVo sysUser){
        AjaxResult ajax = AjaxResult.success();
        // 生成令牌
        String token = loginService.loginMobile(sysUser.getUsername(), sysUser.getPassword());
        ajax.put(Constants.TOKEN, token);
        return ajax;
    }

    /**
     * 获取用户信息
     *
     * @return 用户信息
     */
    @GetMapping("getInfo")
    public AjaxResult getInfo()
    {
        SysUser sysUser=SecurityUtils.getLoginUser().getUser();
        return AjaxResult.success(sysUser);
    }
}
